import { sendMsgToBackground } from "@/utils/chrome";
import { Message } from "element-ui";

export function blobToDataURL(blob, callback) {
  var a = new FileReader();
  a.onload = function (e) {
    callback(e.target.result);
  };
  a.readAsDataURL(blob);
}

export function saveToBlueberryApi({ base64, url, folder }, callBack) {
  sendMsgToBackground(
    { action: "upload-asset-api", data: { base64, url, folder } },
    ({ _success, _msg }) => {
      if (!_success) {
        Message.error({
          customClass: 'el-message-index',
          message:_msg || "操作失败"});
        return;
      }
      if (callBack) {
        callBack();
      }
      Message.success({
        customClass: 'el-message-index',
        message:"操作成功"});
    }
  );
}


export function screenShot( params, callBack) {
  sendMsgToBackground(
    { action: "screen-shot-api", data: params },
    (data => {
      console.log("收到的数据",data)
      if (callBack) {
        console.log("base64")
        setTimeout(() => {
          callBack( data.base64);
        }, 1500)
      }
    })
  );
}
